<!--# layout("/common/layout.html",{"jsBase":"/js/banner/banner/"}){ -->

<form class="layui-form layui-form-pane" id="addForm" enctype="multipart/form-data"  lay-filter="editform">
    <input type="hidden" name="bannerId" id="bannerId">

    <br/>
    <div class="layui-row">
        <div class="layui-form-item">
                <div class="layui-inline">
                <label class="layui-form-label">广告标题</label>
                    <div class="layui-input-inline" style="width: 360px">
                        <input type="text" name="title" id="title" autocomplete="off" maxlength="50" class="layui-input"  lay-verify="required">
                    </div>
                </div>

        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">目标平台</label>
				<div class="layui-input-inline">
                    <layui:simpleDataSelect name="module" value="" data="${moduleList}"
                                            attrId="dictId" attrName="dictValue" layFilter="colFilter" id="module"/>
				</div>
            </div>
            <div class="layui-inline">
            <label class="layui-form-label">归属省份</label>
				<div class="layui-input-inline">
                    <layui:simpleDataSelect name="provId" value="" data="${provinceList}"
                                            attrId="provId" attrName="provName" layFilter="colFilter" id="provId"  laySearch="true"/>
				</div>
            </div>
        </div>

    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">轮播状态</label>
                <div class="layui-input-inline">
                    <select name="status" lay-verify="">
                        <option value="0">新建</option>
                        <option value="1">已上线</option>
                        <option value="2">已下线</option>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">跳转类型</label>
                <div class="layui-input-inline">
                    <select name="type" id="type" lay-verify="required" lay-search=""lay-filter="select_type">
                        <option value="">请选择类型</option>
                        <option value="7">转到产品</option>
                        <option value="1">转到H5地址</option>
                        <option value="2">转到讲座</option>
                        <option value="3">转到资讯</option>
                        <option value="4">转到老师</option>
                        <option value="5">转到小程序</option>
                        <option value="6">不进行跳转</option>
                    </select>
                </div>
            </div>

        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <!--            <div class="layui-inline">-->
            <!--            <label class="layui-form-label">显示归属</label>-->
            <!--				<div class="layui-input-inline">-->
            <!--                    <select name="come" lay-verify="">-->
            <!--                        <option value="1">全部</option>-->
            <!--                        <option value="4">pc</option>-->
            <!--                        <option value="3">问答</option>-->
            <!--                        <option value="2">h5</option>-->
            <!--                    </select>-->
            <!--                </div>-->
            <!--            </div>-->
            <div class="layui-inline">
                <label class="layui-form-label">显示排序</label>
                <div class="layui-input-inline">
                    <input type="text" name="sort" id="sort" autocomplete="off" maxlength="50" class="layui-input"   lay-verify="number">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">跳转地址</label>
                <div class="layui-input-inline" style="width: 590px" >
                    <div id="href1Div"><input type="text" name="displyName" id="href1" autocomplete="off" maxlength="100" class="layui-input"></div>
                    <div id="href2Div" style="display:none;"><select name="displyName1"  id="href2"  lay-verify="required" lay-search=""></select></div>
                    <input type="hidden" name="href" id="href">
                </div>
            </div>
        </div>
    </div>

    <!--<input type="hidden" name="href" id="href" autocomplete="off" maxlength="50" class="layui-input" >-->

    <div class="layui-row">
        <div class="layui-form-item">
            <layui:image id="bannerPath" tagName="轮播图片" tips="图片说明"/>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <layui:image id="shareImg" tagName="分享图片" tips="图片大小 375 * 300"/>
        </div>
    </div>
    <layui:submitButtons id="addButton" />

</form>
<!--#} -->
<script>

Common.initImage();
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
}).define([ 'form', 'laydate', 'table','loading','bannerApi'], function(exports) {
    var form = layui.form;
    var bannerApi = layui.bannerApi;
    var index = layui.index;
    var isNew = true;
    <!--# if(!(isEmpty(bannerJson))){  -->
    isNew = false;
    <!--# } -->
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();

                if( $("#type").val()==1){
                    $("#href").val( $("#href1").val());
                }else {
                    $("#href").val($("#href2").val());
                }
                if( $("#type").val()==1){

                    var shareImg = $("#shareImgView").attr("src");
                    if(shareImg==null||shareImg==''){
                        Common.info("请选择分享图片");
                        return;
                    }
                }

                form.on('submit(form)', function(){
                    bannerApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
    <!--# if(!(isEmpty(bannerJson))){  -->
    var formJson = ${bannerJson};
    form.val("editform",formJson);
    $(".image-preview").each(function() {
        $(this).attr("src",formJson[$(this).attr("id")]);
    });
    <!--# } -->

    form.on('select(select_type)', function(data){
        $('#href1').removeAttr("readonly");
        var dataValue = data.value;
        if(dataValue == 1){
            document.getElementById("href2Div").style.display="none";//隐藏
            document.getElementById("href1Div").style.display="";//显示
        }else if(dataValue == 6){
            document.getElementById("href2Div").style.display="none";//隐藏
            document.getElementById("href1Div").style.display="";//显示
            $("#href1").val("");
            $('#href1').attr("readonly","readonly");
        }else{
          //  $('.mySelect').find('input').removeAttr("readonly");
            var provinceId = $("#provId").val();
            if(provinceId==null || provinceId==""){
                alert("请先选择省份");
                return;
            }
            document.getElementById("href1Div").style.display="none";//隐藏
            document.getElementById("href2Div").style.display="";//显示

            $.getJSON("../banner/dataList.json?typeId="+data.value+"&provinceId="+provinceId, function(data){
                var optionstring = "";
                $.each(data.data, function(i,item){
                    optionstring += "<option value=\"" + item.id + "\">" + item.name + "</option>";
                });
                $("#href2").html('<option value=""></option>' + optionstring);
                form.render('select'); //这个很重要
            });
        }
    });

});



</script>
